package com.tan.androidtest.customview.paint;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;

import com.tan.androidtest.R;

/**
 * 深入了解Paint
 */

public class DemoView2 extends View {


    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    //颜色线下渐变
    private Shader linearShader = new LinearGradient(0, 0, 200, 200, ContextCompat.getColor(getContext(), R.color.red_ff2e31), ContextCompat.getColor(getContext(), R.color.blue_1aacf7), Shader.TileMode.CLAMP);
    //颜色雷达型渐变
    private Shader radialShader = new RadialGradient(100, 100, 100, ContextCompat.getColor(getContext(), R.color.red_ff2e31), ContextCompat.getColor(getContext(), R.color.blue_1aacf7), Shader.TileMode.REPEAT);

    public DemoView2(Context context) {
        super(context);
    }

    public DemoView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DemoView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setShader(radialShader);
        canvas.drawRect(0, 0, 200, 200, mPaint);
    }

}
